package unit3;
/**
 * 
 * @author asus
 *
 */
public class Compoundinterest {
	public static void main(String[] args) {
		final double STARTRATE=10;
		final int NRATES=6;
		final int NYEARS=10;
		
//		set interest rates to 10  
		double[] interestRate=new double[NRATES];
		for(int x=0;x<interestRate.length;x++){
			interestRate[x]=(STARTRATE+x)/100.0;
		}
		double[][] balances=new double[NYEARS][NRATES];
		
//		set initial balances to 10000
		for(int x=0;x<balances[0].length;x++)
			balances[0][x]=10000;
		
//		compute interest for future years
		for(int x=1;x<balances.length;x++){
			for(int y=0;y<balances[x].length;y++){
//				get last year's balances from previous row
				double oldBalance=balances[x-1][y];
				
//				compute interest
				double interest=oldBalance*interestRate[y];
				
//				compute this year's balances
				balances[x][y]=oldBalance+interest;
			}
		}
//		print one row of interest rates
		for(int x=0;x<interestRate.length;x++){
			System.out.printf("%9.0f%%",100*interestRate[x]);
		}
		
		System.out.println();
//		print balance table 
		for(double[] row:balances){
//			print table row
			for(double b:row){
				System.out.printf("%10.2f",b);
			}
			System.out.println();
		}
	}
}
